package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2023/9/12 09:56
 * @apiNote
 */

public class Test00063UniquePathsWithObstacles {

    public int test(int[][] obstacleGrid) {
        int m = obstacleGrid.length;
        int n = obstacleGrid[0].length;
        int[] dp = new int[n];
        dp[0] = obstacleGrid[0][0] == 0 ? 1 : 0;
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                if(obstacleGrid[i][j] == 1){
                    dp[j] = 0;
                    continue;
                }
                if(j - 1 >= 0 && obstacleGrid[i][j - 1] == 0){
                    dp[j] += dp[j - 1];
                }
            }
        }
        return dp[n - 1];
    }



}
